/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentacion;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import logica.cliente.*;
import datos.*;
import java.awt.Dimension;
import java.awt.Point;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.*;
/**
 *
 * @author abel
 */
public class MensajeGlobal extends javax.swing.JFrame{

    private Cliente cliente =null;
  
     private Usuario usuario;
    private ArrayList<String> mensajesescritos;
    /**
     * Creates new form pantalla1
     */
    public MensajeGlobal() {
        initComponents();
        cliente =new Cliente();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jScrollPane2 = new javax.swing.JScrollPane();
        JTPchat = new javax.swing.JTextPane();
        JMBMensajeGlobal = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        JMICerraventana = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Mensaje Global");
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setRequestFocusEnabled(false);

        JTPchat.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        JTPchat.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N
        JTPchat.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTPchatKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                JTPchatKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(JTPchat);

        JMBMensajeGlobal.setMaximumSize(new java.awt.Dimension(56, 100));
        JMBMensajeGlobal.setMinimumSize(new java.awt.Dimension(56, 100));
        JMBMensajeGlobal.setPreferredSize(new java.awt.Dimension(56, 26));

        jMenu1.setText("File");

        JMICerraventana.setText("Cerrar");
        jMenu1.add(JMICerraventana);

        JMBMensajeGlobal.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem3.setText("jMenuItem3");
        jMenu2.add(jMenuItem3);

        JMBMensajeGlobal.add(jMenu2);

        jMenu4.setText("Ayuda");

        jMenuItem2.setText("jMenuItem2");
        jMenu4.add(jMenuItem2);

        JMBMensajeGlobal.add(jMenu4);

        setJMenuBar(JMBMensajeGlobal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JTPchatKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTPchatKeyPressed

        if (evt.getKeyCode()==10)
        {
            
            InetAddress   ip = null;
            cliente= new Cliente();
            try { 
              ip=InetAddress.getLocalHost();
                   
            } catch (UnknownHostException ex) {
                Logger.getLogger(MensajeGlobal.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            usuario=new Usuario(ip.getHostName(),JTPchat.getText(),ip.getHostAddress(),7654,0);
           // cliente.EnviarMensaje(usuario);
          //  mostrarmensajes();
           
            cliente = new Cliente();
            cliente.enviarmensajeglobal(usuario);
           // mostrarmensajes();
            JTPchat.setText("");
           
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_JTPchatKeyPressed
       
   /* public String mensaje()
    {
        String mensaje=JTPchat.getText();
                JTPchat.setText("");
        return mensaje;
    }*/
   
    
    
    
    
    private void JTPchatKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTPchatKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_JTPchatKeyTyped

    public void memoria()
    {
        
    }
    
     /**
     * @param args the command line arguments
     */
    
    
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MensajeGlobal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MensajeGlobal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MensajeGlobal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MensajeGlobal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MensajeGlobal().setVisible(true);
                
               
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar JMBMensajeGlobal;
    private javax.swing.JMenuItem JMICerraventana;
    private javax.swing.JTextPane JTPchat;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
